home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Technology Seed / Jan. '98 ATS.toast / NavServices1.0b3 / Navigation Services SDK / Examples / Sampler / Sampler ƒ / Template.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  3.9 KB  |  177 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Template.c
  3.  
  4.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment AppSeg
  9.  
  10. #ifndef __GESTALT__
  11. #include <Gestalt.h>
  12. #endif
  13.  
  14. #ifndef Common_Defs
  15. #include "Common.h"
  16. #endif
  17.  
  18. short        gQuit, gQuitting;
  19. short        gDocumentCount;
  20. Document*    gDocumentList[kMaxDocumentCount];
  21. short        gFontItem, gSizeItem;
  22. short        gInBackground;
  23. Document*    gFrontDocument;
  24. short        gCanUndoDrag;
  25. WindowPtr    gUndoFrontmost, gLastFrontmost;
  26. Boolean        gCanDrag;
  27. Boolean        gCanPrint;
  28. THPrint        gPrintRecord;
  29. Boolean        gNavServicesExists;
  30.  
  31. // AppleEvent handlers:
  32. AEEventHandlerUPP    myODOCEventHandler;
  33. AEEventHandlerUPP    myQAPPEventHandler;
  34. AEEventHandlerUPP    myOAPPEventHandler;
  35. ControlActionUPP     myActionProcUPP;
  36.  
  37. // for MixedMode:
  38. #ifndef NewEventHandlerProc
  39.     #define NewEventHandlerProc(x) (EventHandlerProcPtr)x
  40. #endif
  41.  
  42. // prototypes:
  43. void InitializeToolbox(void);
  44. void InitializeGlobals(void);
  45. void SetupMenus(void);
  46. void InstallEventHandlers(void);
  47.  
  48.  
  49. // *****************************************************************************
  50. // *
  51. // *    InitializeToolbox()
  52. // *
  53. // *****************************************************************************
  54. void InitializeToolbox()
  55. {    
  56.     InitGraf(&qd.thePort);
  57.     InitFonts();
  58.     InitWindows();
  59.     InitMenus();
  60.     TEInit();
  61.     InitDialogs(0L);
  62.     InitCursor();
  63.  
  64.     MoreMasters();
  65.     MoreMasters();
  66.     MaxApplZone();
  67.  
  68.     FlushEvents(everyEvent,0);
  69. }
  70.  
  71.  
  72. // *****************************************************************************
  73. // *
  74. // *    InitializeGlobals()
  75. // *
  76. // *****************************************************************************
  77. void InitializeGlobals()
  78. {    
  79.     long result = 0;
  80.  
  81.     gQuit             = gQuitting = false;
  82.     gDocumentCount     = 0;
  83.     gFontItem         = gSizeItem = 0;
  84.     gInBackground     = false;
  85.     gCanUndoDrag     = slCantUndo;
  86.     gPrintRecord    = nil;
  87.  
  88.     if ((Gestalt(gestaltDragMgrAttr,&result) != noErr) || (!(result & (1 << gestaltDragMgrPresent))))
  89.         gCanDrag = false;
  90.     else
  91.         gCanDrag = true;
  92.  
  93.     gCanPrint = false;
  94.  
  95.     // Check for Navigation Services 
  96.     gNavServicesExists = NavServicesAvailable();
  97. }
  98.  
  99.  
  100. // *****************************************************************************
  101. // *
  102. // *    SetupMenus()
  103. // *
  104. // *****************************************************************************
  105. void SetupMenus()
  106. {    
  107.     Handle        theMenuBar;
  108.     Str255        theStr;
  109.  
  110.     theMenuBar = GetNewMBar(MenuBarID);
  111.  
  112.     SetMenuBar(theMenuBar);
  113.     DisposeHandle(theMenuBar);
  114.  
  115.     AppendResMenu(GetMenuHandle(idAppleMenu),'DRVR');
  116.  
  117.     GetIndString(theStr,MenuStringsID,slCantUndo);
  118.     SetMenuItemText(GetMenuHandle(idEditMenu),iUndo,theStr);
  119.  
  120.     DrawMenuBar();
  121. }
  122.  
  123.  
  124. // *****************************************************************************
  125. // *
  126. // *    InstallEventHandlers()
  127. // *
  128. // *****************************************************************************
  129. void InstallEventHandlers()
  130. {
  131.     long     result = 0;
  132.     OSErr     theErr = noErr;
  133.     
  134.     theErr = Gestalt(gestaltAppleEventsAttr,&result);
  135.     if (theErr == noErr)
  136.         {
  137.         myODOCEventHandler = NewAEEventHandlerProc(MyHandleODOC);
  138.         myQAPPEventHandler = NewAEEventHandlerProc(MyHandleQUIT);
  139.         myOAPPEventHandler = NewAEEventHandlerProc(MyHandleOAPP);
  140.  
  141.         (void)AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,myOAPPEventHandler,0,false);    
  142.         (void)AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,myQAPPEventHandler,0,false);
  143.         (void)AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,myODOCEventHandler,0,false);
  144.         }
  145. }
  146.  
  147.  
  148. // *****************************************************************************
  149. main()
  150. {
  151.     long result = 0;
  152.     OSErr theErr = noErr;
  153.     
  154.     InitializeToolbox();
  155.     InitializeGlobals();
  156.     InstallEventHandlers();
  157.     SetupMenus();
  158.     
  159.     myActionProcUPP = NewControlActionProc(ScrollProc);
  160.  
  161.     AdjustMenus();
  162.  
  163.     EventLoop();
  164.  
  165.     theErr = Gestalt(gestaltAppleEventsAttr,&result);
  166.     if (theErr != noErr)
  167.         {
  168.         DisposeRoutineDescriptor(myODOCEventHandler);
  169.         DisposeRoutineDescriptor(myQAPPEventHandler);
  170.         DisposeRoutineDescriptor(myOAPPEventHandler);
  171.         }
  172.  
  173.     DisposeRoutineDescriptor(myActionProcUPP);
  174.  
  175.     return 0;
  176. }
  177.